<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>签到活动列表</title>
    <!--{include file='comm/comm_cal.tpl'}-->
</head>
<body>

<!--{include file='comm/naviBanner.tpl'}-->

<style>

    .opa{opacity: 0.5;}

    #addBox tr th{
        border-collapse: collapse;
        background-color: #EAEAEA;
        border: 1px solid #CCCCCC;
        height:28px;
        text-align: center;
    }

    #addBox tr td{
        border: 1px solid #CCCCCC;
        padding:3px;
    }

</style>

<div class="ebsig_container">

    <!--{include file='comm/menu.tpl'}-->

	<div class="comm_crub">
	    <span class="now_crub">签到活动列表</span>
	</div>
	
	<div class="comm_content">
	
	    <div  class="search-box">
	        <form id="searchForm" onsubmit="return false;">
	            <div style="position:relative">
	                 <span>
	                    活动主题：<input type="text" name="name" id="name">
	                </span>
	                <span>
	                    活动时间：<input type="text" style="width: 120px;" readonly="readonly" name="start_Date" id="start_Date">
	                    ～
	                    <input type="text" style="width: 120px;" readonly="readonly" name="end_Date" id="end_Date">
	                </span>
	                <span>
	                    <input type="button" class="btn" value="查询" onclick="signed.search();">&nbsp;&nbsp;
	                    <input class="btn" type="button" onclick="signed.clear();" value="重置">
	                </span>
	            </div>
	        </form>
	    </div>
	
	    <table id="flex" style="display:none"></table>
	
	</div>

    

</div>

<div id="check_in_edit" style="display: none;">

    <form id="editForm" name="editForm">

        <div class="input-group input-group-lg">
            <span class="input-group-addon">活动名称：</span>
            <input type="text" class="form-control" name="promotionName" id="promotionName" placeholder="活动名称">
            <span class="red"> *</span>
        </div>

        <div class="input-group input-group-lg">
            <span class="input-group-addon">活动日期：</span>
            <span class="input-group-radio">
                <input type="text" name="startDate" id="startDate" placeholder="开始日期">
                ~
                <input type="text" name="endDate" id="endDate" placeholder="结束日期">
            </span>&nbsp;<span class="red">*</span>
        </div>

        <div class="input-group input-group-lg">
            <span class="input-group-addon">活动描述：</span>
            <textarea class="input-group-textarea" name="description" id="description" placeholder="活动描述"></textarea>
        </div>

        <div class="input-group input-group-lg">
            <span class="input-group-addon">赠送积分：</span>
            <input type="text" class="form-control" name="points" id="points" placeholder="赠送积分" maxlength="4">
            <span class="red"> *</span>
        </div>

        <div class="input-group input-group-lg">
            <span class="input-group-addon">连续签到天数：</span>
            <input type="text" class="form-control" name="continuousDay" id="continuousDay" placeholder="额外赠送积分不为空时，该字段必须填写" maxlength="4">
        </div>

        <div class="input-group input-group-lg">
            <span class="input-group-addon">额外赠送积分：</span>
            <input type="text" class="form-control" name="extraPoints" id="extraPoints" placeholder="连续签到天数不为空时，该字段必须填写" maxlength="4">
        </div>
        <input type="hidden" name="promotionID" id="promotionID" value="0"/>

    </form>

</div>

<script type="text/javascript">

    $("#flex").flexigrid({
        url:"/invokingAjax-backend/promotion/signedTo.ajax?operFlg=1&xjx=none",
                dataType: "json",
            colModel : [
                    <!--{if $edit_permission}-->
                {display: "操作", width : 60, align: 'center'},
                    <!--{/if}-->
        {display: "活动名称", width : 238, align: 'left'},
        {display: "开始日期", width : 100, align : 'center' },
        {display: "结束日期", width : 100, align: 'center'},
        {display: "赠送积分", width : 80, align: 'center'},
        {display: "额外赠送", width : 200},
        {display: "使用状态", width :80, align: 'center'},
        {display: "描述", width :300}
    ],
        <!--{if $edit_permission}-->
        buttons : [
            {name: "添加", bclass: "add", onpress : "signed.edit.open"},
            {separator: true},
            {name: "删除", bclass: "delete", onpress : "signed.del.check"}
        ],
        <!--{/if}-->
        sortname: "promotionID",
        sortorder: "desc",
        usepager: true,
        rp: 10,
        useRp: true,
        onSubmit: function() {
            var dt = $('#searchForm').serializeArray();
            $("#flex").flexOptions({params: dt});
            return true;
        }
    });


    var signed = {

        edit: {

            open: function() {

                E.popup.open({
                    id: 'check_in_edit',
                    btnName: '保存',
                    btnCall: 'signed.edit.check();'
                });

                $("#startDate").datetimepicker();
                $("#endDate").datetimepicker();

            },

            search: function( id ) {

                E.loadding.open('正在查询，请稍候...');
                E.ajax_get({
                    url: '/invokingAjax-backend/promotion/signedTo.ajax?operFlg=6',
                    data: {
                        id: id
                    },
                    call: 'signed.edit.searchResult'
                });

            },

            searchResult: function( o ) {

                E.loadding.close();
                if (o.code == 200) {
                    this.open(o.data);
                    $('#promotionID').val(o.data.promotionID);
                    $('#promotionName').val(o.data.promotionName);
                    $('#description').val(o.data.description);
                    $('#startDate').val(o.data.startDate);
                    $('#endDate').val(o.data.endDate);
                    $('#points').val(o.data.points);
                    if (o.data.continuousDay > 0) {
                        $('#continuousDay').val(o.data.continuousDay);
                        $('#extraPoints').val(o.data.extraPoints);
                    }
                } else {
                    E.alert(o.messgae);
                }

            },

            check: function() {

                this.dt = E.getFormValues('editForm');
                var error_msg = '';

                if (E.isEmpty(this.dt.promotionName)) {
                    error_msg += '活动名称不能为空<br>';
                }
                if (E.isEmpty(this.dt.startDate) || E.isEmpty(this.dt.endDate)) {
                    error_msg += '请选择活动开始和结束日期<br>';
                }
                if (!E.dateCompare(this.dt.startDate, this.dt.endDate)) {
                    error_msg += '开始日期不能大于结束日期<br>';
                }
                if (!E.isDigital(this.dt.points) || this.dt.points <= 0 || this.dt.continuousDay.length > 4) {
                    error_msg += '赠送积分不能为空且是大于0的4位整数<br>';
                }
                if (!E.isEmpty(this.dt.continuousDay)) {
                    if (!E.isDigital(this.dt.continuousDay) || this.dt.continuousDay <= 0 || this.dt.continuousDay.length > 4) {
                        error_msg += '连续签到天数必须是大于0的4位整数<br>';
                    } else if (!E.isDigital(this.dt.extraPoints) || this.dt.points <= 0 || this.dt.points.length > 4) {
                        error_msg += '额外赠送积分不能为空且是大于0的4位整数<br>';
                    }
                } else if (!E.isEmpty(this.dt.extraPoints)) {
                    if (!E.isDigital(this.dt.extraPoints) || this.dt.extraPoints <= 0 || this.dt.extraPoints.length > 4) {
                        error_msg += '额外赠送积分必须是大于0的4位整数<br>';
                    } else if (!E.isDigital(this.dt.continuousDay) || this.dt.continuousDay <= 0 || this.dt.continuousDay.length > 4) {
                        error_msg += '连续签到天数不能为空且是大于0的4位整数<br>';
                    }
                }

                if (error_msg != '') {
                    E.alert(error_msg);
                } else {
                    E.loadding.open('正在保存，请稍候...');
                    E.ajax_post({
                        url: '/invokingAjax-backend/promotion/signedTo.ajax?operFlg=2',
                        data: this.dt,
                        call: 'signed.edit.result'
                    });
                }

            },

            result: function( o ) {
                E.loadding.close();
                if (o.code == 200) {
                    signed.load();
                    if (this.dt.promotionID == 0) {
                        E.alert('保存成功', 2);
                        document.getElementById('editForm').reset();
                    } else {
                        E.alert('保存成功', 2, 'E.popup.close');
                    }
                } else {
                    E.alert(o.message);
                }
            }

        },

        del: {

            check: function() {
                if ($('.trSelected').length ==0) {
                    E.alert('请选择要删除的签到活动');
                } else {
                    E.confirm("您确认删除选中的签到活动吗?",'signed.del.execute')
                }
            },

            execute: function() {
                E.loadding.open('正在删除，请稍候...');
                var pidArr = new Array();
                $('.trSelected').each(function(k,v){
                    var id = $(v).attr('id').replace('row', '');
                    pidArr.push(id);
                });
                E.ajax_post({
                    url: '/invokingAjax-backend/promotion/signedTo.ajax?operFlg=4',
                    data: {
                        pid: pidArr
                    },
                    call: "signed.del.result"
                });
            },

            result: function( o ) {
                E.loadding.close();
                if(o.code == 200){
                    E.alert(o.message,2);
                    signed.load();
                }else{
                    E.alert(o.message);
                }
            }

        },

        use: {

            check: function( promotionID, useFlg ) {
                this.promotionID = promotionID;
                this.useFlg = useFlg;
                if (useFlg == 1) {
                    E.confirm('您确认要启用该签到活动吗？','signed.use.execute')
                } else {
                    E.confirm('您确认要禁用该签到活动吗？','signed.use.execute')
                }
            },

            execute: function() {
                if (this.useFlg) {
                    E.loadding.open('正在启用，请稍候...');
                } else {
                    E.loadding.open('正在禁用，请稍候...');
                }
                E.ajax_post({
                    url: '/invokingAjax-backend/promotion/signedTo.ajax?operFlg=3',
                    data: {
                        promotionID: this.promotionID,
                        useFlg: this.useFlg
                    },
                    call: "signed.use.result"
                });
            },

            result: function( o ) {
                E.loadding.close();
                if(o.code == 200){
                    E.alert(o.message,2);
                    signed.load();
                }else{
                    E.alert(o.message);
                }
            }

        },

        load:function(){
            $("#flex").flexReload();
        },

        search: function() {
            var dt = $("#search_form").serializeArray();
            $("#flex").flexOptions({params: dt, page: 1}).flexReload();
        }

    };

    $("#start_Date").datetimepicker();
    $("#end_Date").datetimepicker();

</script>

</body>
</html>